package com.py.androidUtils.base;

import android.content.Context;
import android.os.Build;
import android.os.StrictMode;

import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.py.androidUtils.log.ExceptionHandlerApplocation;

/**
 * @说明 公用Application
 * @作者 LY
 * @文件 BaseApplication.java
 * @时间 2015年6月25日 上午10:11:33
 * @版权 Copyright(c) 2015 LY-版权所有
 * @email dengdai.ly@qq.com
 */
public class BaseApplication extends ExceptionHandlerApplocation {
	private boolean hasNetWork; // 网络状态
	private String netWorkType = ""; // 是2G、WIFI和3G
	public static BaseApplication application;
	public static final boolean DEVELOPER_MODE = false;

	@Override
	public void onCreate() {
		initImageLoader(this);
		application = this;
		super.onCreate();
	}

	/********* LoadImages **********/

	/**
	 * 加载图片初始化配置
	 * 
	 * @param context
	 */
	@SuppressWarnings("unused")
	public static void initImageLoader(Context context) {
		if (DEVELOPER_MODE && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
			StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyDialog().build());
			StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyDeath().build());
		}
		ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context);
		config.threadPriority(Thread.NORM_PRIORITY - 2);
		config.denyCacheImageMultipleSizesInMemory();
		config.diskCacheFileNameGenerator(new Md5FileNameGenerator());
		config.diskCacheSize(50 * 1024 * 1024);
		config.tasksProcessingOrder(QueueProcessingType.LIFO);
		config.writeDebugLogs();
		ImageLoader.getInstance().init(config.build());
	}

	/********* LoadImages End **********/

	/********** 网络 **********/
	public boolean isHasNetWork() {
		return hasNetWork;
	}

	public void setHasNetWork(boolean hasNetWork) {
		this.hasNetWork = hasNetWork;
	}

	public String getNetWorkType() {
		return netWorkType;
	}

	public void setNetWorkType(String netWorkType) {
		this.netWorkType = netWorkType;
	}
	/********** 网络 end **********/
}
